require('./PageSelectinfo.styl');
const { RadioField } = SaltUI;
import { Control } from 'react-keeper'
const ui = require('clientConfig/util/jsapi/ui');
class Selectinfo extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            value: ''
        };
    }
    handleChange(value) {
        // 数据确认变更
        this.setState({
            value: value
        });
    }
    selected() {
        let id = this.props.params.id;
        let type = this.props.params.type || Control.state.type;
        if (type == '1') {
            Control.go('/home', { id, content: this.value })
        } else if (type == '0') {
            Control.go('/bind/modify/fill', { id, content: this.value });
        }
    }
    render() {
        let t = this;
        if ((this.props.params.id).toString().length == 1) {
            var radioFieldProps = {
                data: [
                    {
                        value: '1',
                        checked: false,
                        text: '男',
                        disable: false,
                    },
                    {
                        value: '2',
                        checked: false,
                        text: '女',
                        disable: false,
                    },
                ],
                onChange(value, index, data) {
                    t.value = data[index].text;
                    t.selected()
                },
                groupListArgument: {
                    lineIndent: 15,
                    itemIndent: 15,
                },
                label: '',
                groupListFlag: true,
                className: ''
            };
        } else if ((this.props.params.id).toString().length == 6) {
            var cityList = require('clientConfig/city.json');
            for (let key in cityList) {
                if (key == (this.props.params.id).toString()) {
                    var data = cityList[key];
                }
            }
            var radioFieldProps = {
                data: data,
                onChange(value, index, data) {
                    t.value = data[index].text;
                    console.log('daye=' + t.props.params.city)
                    if (t.props.params.city) {
                        t.value += ' ' + decodeURIComponent(t.props.params.city);
                    }
                    t.selected()
                },
                groupListArgument: {
                    lineIndent: 15,
                    itemIndent: 15,
                },
                label: '',
                groupListFlag: true,
                className: ''
            };
        }
        return (
            <div className="selectinfo">
                <RadioField {...radioFieldProps} />
            </div>
        );
    }
    setui() {
        ui.setNavigationRight({ text: '完成', control: true, show: true }, (isSuccessed, result) => {
            if (isSuccessed) {
                let id = this.props.params.id;
                let type = this.props.params.type || Control.state.type;
                // alert(type)
                if (type == '1') {
                    // alert(JSON.stringify({ id, content: this.state.name }))
                    Control.go('/home', { id, content: this.state.name })
                } else if (type == '0') {
                    Control.go('/bind/modify/fill', { id, content: this.state.name });
                }
                // console.log(Control)
                // 

            }
        })
    }
    componentWillMount() {
        ui.setLeft({ control: true, text: '返回' }, (isSuccessed, result) => {
            // if (isSuccessed) {
            //     Control.go(-1)
            // }
            if (isSuccessed) {
                let id = this.props.params.id;
                let type = this.props.params.type || Control.state.type;
                // alert(type)
                if (type == '1') {
                    // alert(JSON.stringify({ id, content: this.state.name }))
                    Control.go('/home', { id, content: this.value })
                } else if (type == '0') {
                    Control.go('/bind/modify/fill', { id, content: this.value });
                }
            }
        })
    }

    componentDidMount() {
        ui.setNavigationRight({ text: '完成', control: true }, (isSuccessed, result) => {
            debugger
            if (isSuccessed) {
                let id = this.props.params.id;
                let type = this.props.params.type || Control.state.type;
                // alert(type)
                if (type == '1') {
                    // alert(JSON.stringify({ id, content: this.state.name }))
                    Control.go('/home', { id, content: this.value })
                } else if (type == '0') {
                    Control.go('/bind/modify/fill', { id, content: this.value });
                }
            }
        })
    }

    componentWillReceiveProps(nextProps) {
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {

    }
}

module.exports = Selectinfo;
